package com.itheima.health.dao;

import com.itheima.health.dto.OrderVo;
import com.itheima.health.dto.SmsLoginParam;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.Member;
import com.itheima.health.pojo.Order;
import com.itheima.health.pojo.Setmeal;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface SendDao {
    @Select("select count(*) from t_smslogin where telephone=#{telephone}")
    Integer isNot(String telephone);

    @Insert("insert into t_smslogin(telephone, validateCode) values (#{telephone},#{validateCode})")
    void insert(SmsLoginParam smsLoginParam);

    void update(SmsLoginParam smsLoginParam);

    @Select("select validateCode from t_smslogin where telephone =#{telephone}")
    String check(String telephone);

    @Select("select * from setmeal")
    List<Setmeal> select();

    @Select("select * from setmeal where id=#{id}")
    Setmeal findById(Integer id);

    @Select("select checkgroup_id from t_setmeal_checkgroup where setmeal_id =#{id}")
    Integer[] findCheckGroupId(Integer id);

    @Select("select count(*) from t_member where phoneNumber =#{telephone} ")
    Integer iN(String telephone);

    @Insert("insert into t_member(fileNumber, name, sex, idCard, phoneNumber, regTime, password, email, birthday, remark) " +
            "VALUES (#{fileNumber},#{name},#{sex},#{idCard},#{phoneNumber},#{regTime},#{password},#{email},#{birthday},#{remark})")
    void into(Member member);

    void edit(Member member);
    @Select("select id from t_member where phoneNumber =#{telephone}")
    Integer selectIdByPhone(String telephone);
    @Select("select count(*) from t_order where memberId =#{memberId} and orderDate= #{orderDate} ")
    Integer checkRepeat(Integer memberId, Date orderDate);


    @Insert("insert into t_order(memberId, orderDate, orderType, orderStatus, setmealId) " +
            "VALUES (#{memberId},#{orderDate},#{orderType},#{orderStatus},#{setmealId})")
    void insertOrder(Order order);


    @Select("select id from t_member where idCard =#{idCard}")
    Integer selectMemberId(String idCard);

    @Select("select * from t_order where memberId =#{memberId} and orderDate =#{orderDate}")
    Order selectOrder(Integer memberId, Date orderDate);

    @Select("select * from t_order where id =#{id}")
    Order selectOrderById(Integer id);

    @Select("select name from t_member where id =#{memberId}")
    String selectMemberById(Integer memberId);
}
